<template>
  <div>
    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input
              v-model="TempName"
              clearable
              @clear="clearFunc"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" icon="el-icon-search" style="float: left" @click="search" >搜索
          </el-button>
          <el-button type="primary" style="float: left" @click="centerDialogVisible = true">添加</el-button>
        </el-col>
        <!--        <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>-->
        <!--        <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>-->
      </el-row>
      <template>
        <el-table
            border
            :data="tableData"
            style="width: 100%">
          <el-table-column
              prop="name"
              label="姓名">
          </el-table-column>
          <el-table-column
              prop="phonenumber"
              label="电话">
          </el-table-column>
          <el-table-column
              prop="address"
              label="地址">
          </el-table-column>
        </el-table>
      </template>
    </el-card>

    <el-dialog
        title="添加数据界面"
        v-show="centerDialogVisible"
        width="30%"
        center>

      <template #footer>
      <span class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  data() {
    return {
      TempName: "",
      tableData: [],
      TempTable: [],
      centerDialogVisible: false
    }
  },

  methods: {
    async getUserList() {
      var ret = await this.$axios.post('http://127.0.0.1/sales/customers/');
      console.log(ret)
      for (var i = 0; i < ret.data.length; i++) {
        this.tableData.push(ret.data[i].fields)
      }
      // debugger
      console.log(this.tableData)
    },

    clearFunc(){
        this.getUserList()
    },

    search() {
      if (this.TempName == "") {
        this.TempTable = this.tableData
      } else {
        for (var i = 0; i < this.tableData.length; i++) {
          var temp = this.tableData[i];
          if (temp.name === this.TempName) {
            this.TempTable.push(temp)
            this.tableData = this.TempTable
            // return
          }
        }
      }
    }
  },

  created() {
    this.getUserList();
  }

}
</script>

<style scoped>
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 100%;
  height: 480px;
}

.el-row {
  margin-bottom: 20px;

&
:last-child {
  margin-bottom: 0;
}

}
.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: #99a9bf;
}

.bg-purple {
  background: #d3dce6;
}

.bg-purple-light {
  background: #e5e9f2;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>